home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12413 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: sooner.net!usenet
  2. From: Eddie Bush <edwbush@sooner.net>
  3. Newsgroups: comp.lang.c
  4. Subject: Passing Function Pointers
  5. Date: Sun, 31 Mar 1996 03:54:44 -0800
  6. Organization: sooner.net news site
  7. Message-ID: <315E7284.479F@sooner.net>
  8. NNTP-Posting-Host: p28.sooner.net
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0 (Win16; I)
  13.  
  14. I have a segment of code that is meant to delete a node out of a linked 
  15. list [type *list - this instance is *my_list].  The deal is, I am 
  16. structuring this somewhat in a database form.  I am building this ADT 
  17. (priority queue), and want the user to be able to do whatever they wish 
  18. with the node being deleted.  I couldn't think of any way to pass the 
  19. node back to the calling function, so, instead, I decided that I would 
  20. allow the user to pass in a function and then call that function inside 
  21. the delete function - using the soon to be deleted node as a parameter.  
  22. This way, the user can do whatever they want with the node, and I don't 
  23. have to worry about passing it back to the calling function.
  24. I have used this technique under UN*X platforms using gcc to compile, and 
  25. it works just fine.  It has been a while since I've done it though, so I 
  26. am thinking that maybe it is not just perfectly correct or something.  
  27. Anyhow, here it is:
  28.  
  29. void delete (list *my_list, int *fn){
  30.   
  31.   l_node temp_node = (*my_list) -> head;
  32.   
  33.   if (!is_empty(*my_list)){
  34.     (*my_list) -> head = (*my_list) -> head -> next;
  35.     (*my_list) -> head -> pre = NULL;
  36.   }
  37.   (*fn) (temp_node);
  38.   free (temp_node);
  39. }
  40.  
  41. I made *fn an int because it didn't like the void, and now instead of 
  42. complaining about that it complains about - well, here's the error 
  43. message:
  44.  
  45. Error LIST.H 71:  Call to nonfunction.
  46.  
  47. Any ideas?  It isn't 'clicking' for me.  Is this something to do with the 
  48. version (Borland C/C++ 3.0) I am running maybe?  I passed pointers to 
  49. functions fine using the gcc compiler!
  50.  
  51. Anything would be appreciated!
  52.  
  53. Thanx in Advance!
  54.  
  55. Eddie Bush
  56.